home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Miscellaneous things for converse mode *)
- (* *)
- (* Copyright 1988, 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- {$DEFINE POINT_CHK}
- {$DEFINE FREE_CHK}
-
- UNIT BBCONVM;
-
- INTERFACE
-
- USES
- bbdummy;
-
- PROCEDURE add_c_string(to_tcb : tcb_ptr; in_str : str_ptr; in_type : BYTE);
-
- PROCEDURE add_c_long (to_tcb : tcb_ptr; in_sm : str_mixed_ptr);
-
- PROCEDURE add_c_ub (to_tcb : tcb_ptr; in_place : POINTER; in_cnt : WORD);
-
- PROCEDURE del_c_string(this_tcb : tcb_ptr);
-
- PROCEDURE drop_conv (this_tcb : tcb_ptr);
-
- IMPLEMENTATION
-
- USES
- bbmisc3;
-
- (*===========================================================================*)
- (* Internal subroutine to add something to the chain *)
- (*===========================================================================*)
-
- PROCEDURE add_c_chain (to_tcb : tcb_ptr; in_scb : str_m_chain);
-
- VAR
- last_scb : str_m_chain;
-
- BEGIN;
-
- {$IFDEF DEBUG}
- WRITELN('Chain add from ', active_tcb^.port_chan_s, ' to ',
- to_tcb^.port_chan_s);
- WRITELN('data=', LENGTH(in_scb^.str_m_data.str_data), '=',
- in_scb^.str_m_data.str_data);
- {$ENDIF}
-
- {$IFDEF POINT_CHK}
- test_pointer(to_tcb);
- test_pointer(in_scb);
- {$ENDIF}
-
- in_scb^.str_m_next := NIL;
-
- last_scb := to_tcb^.c_input;
- IF last_scb <> NIL THEN
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(last_scb);
- {$ENDIF}
-
- WHILE last_scb^.str_m_next <> NIL DO
- BEGIN;
- {$IFDEF POINT_CHK}
- test_pointer(last_scb);
- {$ENDIF}
- last_scb := last_scb^.str_m_next;
- END;
-
- {$IFDEF POINT_CHK}
- test_pointer(last_scb);
- {$ENDIF}
-
- last_scb^.str_m_next := in_scb;
-
- END
- ELSE
- to_tcb^.c_input := in_scb;
-
- END;
-
- (*===========================================================================*)
- (* Add string to converse tasks' input chains *)
- (*===========================================================================*)
-
- PROCEDURE add_c_long (to_tcb : tcb_ptr; in_sm : str_mixed_ptr);
-
- VAR
- i : WORD;
- work_scb : str_m_chain;
-
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(to_tcb);
- test_pointer(in_sm);
- {$ENDIF}
-
- i := in_sm^.long_length + str_m_block_oh;
- GETMEM(work_scb, i);
-
- MOVE(in_sm^, work_scb^.str_m_data, str_m_oh + in_sm^.long_length);
- work_scb^.str_m_type := 1;
-
- add_c_chain(to_tcb, work_scb);
-
- END;
-
- (*===========================================================================*)
- (* Add string to converse tasks' input chains *)
- (*===========================================================================*)
-
- PROCEDURE add_c_string(to_tcb : tcb_ptr; in_str : str_ptr; in_type : BYTE);
-
- VAR
- i : WORD;
- work_scb : str_m_chain;
-
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(to_tcb);
- test_pointer(in_str);
- {$ENDIF}
-
- i := LENGTH(in_str^) + str_m_block_oh;
- GETMEM(work_scb, i);
-
- work_scb^.str_m_data.str_data := in_str^;
- work_scb^.str_m_data.long_length := LENGTH(in_str^);
- work_scb^.str_m_type := in_type;
-
- add_c_chain(to_tcb, work_scb);
-
- END;
-
- (*===========================================================================*)
- (* Add unblocked data yo a converse tasks' input chains *)
- (*===========================================================================*)
-
- PROCEDURE add_c_ub (to_tcb : tcb_ptr; in_place : POINTER; in_cnt : WORD);
-
- VAR
- i : WORD;
- work_scb : str_m_chain;
-
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(to_tcb);
- test_pointer(in_place);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Get size of data block needed and the get the block *)
- (*-----------------------------------------------------------------------*)
-
- i := in_cnt + str_m_block_oh;
- GETMEM(work_scb, i);
-
- (*-----------------------------------------------------------------------*)
- (* Initialize the fields *)
- (*-----------------------------------------------------------------------*)
-
- work_scb^.str_m_data.long_length := in_cnt;
- work_scb^.str_m_type := 1;
-
- (*-----------------------------------------------------------------------*)
- (* Move the data *)
- (*-----------------------------------------------------------------------*)
-
- MOVE(in_place^, work_scb^.str_m_data.long_data, in_cnt);
-
- (*-----------------------------------------------------------------------*)
- (* Set string length *)
- (*-----------------------------------------------------------------------*)
-
- IF in_cnt > 255 THEN
- in_cnt := 255;
-
- work_scb^.str_m_data.str_data[0] := CHR(in_cnt);
-
- (*-----------------------------------------------------------------------*)
- (* Chain it on *)
- (*-----------------------------------------------------------------------*)
-
- add_c_chain(to_tcb, work_scb);
-
- END;
-
- (*===========================================================================*)
- (* Remove top string from a task's converse input chain *)
- (*===========================================================================*)
-
- PROCEDURE del_c_string(this_tcb : tcb_ptr);
-
- VAR
- i : WORD;
- work_scb : str_m_chain;
-
- BEGIN;
-
- work_scb := this_tcb^.c_input;
- IF work_scb = NIL THEN EXIT;
-
- {$IFDEF POINT_CHK}
- test_pointer(this_tcb);
- test_pointer(work_scb);
- {$ENDIF}
-
- this_tcb^.c_input := work_scb^.str_m_next;
-
- i := work_scb^.str_m_data.long_length + str_m_block_oh;
-
- FREEMEM(work_scb, i);
-
- {$IFDEF FREE_CHK}
- test_free_list;
- {$ENDIF}
-
- END;
-
- (*===========================================================================*)
- (* Drop a conversation *)
- (*===========================================================================*)
-
- PROCEDURE drop_conv(this_tcb : tcb_ptr);
-
- VAR
- work_tcb : tcb_ptr;
-
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(this_tcb);
- {$ENDIF}
-
- IF this_tcb^.conv_tcb = NIL THEN EXIT;
-
- IF this_tcb^.conv_tcb^.conv_tcb = this_tcb THEN
- this_tcb^.conv_tcb^.conv_tcb := NIL
- ELSE
- BEGIN;
- work_tcb := this_tcb^.conv_tcb;
-
- {$IFDEF POINT_CHK}
- test_pointer(work_tcb);
- {$ENDIF}
-
- WHILE work_tcb^.conv_tcb <> this_tcb DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(work_tcb);
- {$ENDIF}
-
- work_tcb := work_tcb^.conv_tcb;
-
- END;
-
- {$IFDEF POINT_CHK}
- test_pointer(work_tcb);
- {$ENDIF}
-
- work_tcb^.conv_tcb := this_tcb^.conv_tcb;
- END;
-
- this_tcb^.conv_tcb := NIL;
-
- END;
-
- END.